package tcpfileupadatedemo4;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.*;

/**
 * Created by L.jp
 * Description:
 * User: 86189
 * Date: 2022-08-09
 * Time: 17:40
 */

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(1000);
        ThreadPoolExecutor pool=new ThreadPoolExecutor(
                3,  //核心线程数量
                10, //线程池的总数量
                100,//临时线程空闲时间
                TimeUnit.SECONDS, //临时线程空闲时间的单位
                new ArrayBlockingQueue<>(5),//阻塞队列
                Executors.defaultThreadFactory(),//创建线程的方式
                new ThreadPoolExecutor.AbortPolicy()//任务拒绝策略
        );
        while (true) {
            Socket accept = serverSocket.accept();
            ThreadSocket threadSocket = new ThreadSocket(accept);
            //new Thread(threadSocket).start();
            pool.submit(threadSocket);
        }
        
    }
}
